package io.cici.cc.mybatis.plus.core.batch;

import io.cici.cc.mybatis.lite.executor.BatchResult;
import io.cici.cc.mybatis.lite.session.Session;

import java.util.ArrayList;
import java.util.List;

/**
 * 当使用Batch混合查询时,每次都会将原来的结果集清空,建议使用Batch时就不要混合使用select了 (后面看看要不要改成动态代理把...)
 */
public class BatchSqlSession {

    private final Session session;

    private final List<BatchResult> resultBatchList = new ArrayList<>();

    public BatchSqlSession(Session session) {
        this.session = session;
    }

    public <T> T selectOne(String statement) {
        resultBatchList.addAll(session.flushStatements());
        return session.selectOne(statement);
    }

    public <T> T selectOne(String statement, Object parameter) {
        resultBatchList.addAll(session.flushStatements());
        return session.selectOne(statement, parameter);
    }

    public <E> List<E> selectList(String statement) {
        resultBatchList.addAll(session.flushStatements());
        return session.selectList(statement);
    }

    public <E> List<E> selectList(String statement, Object parameter) {
        resultBatchList.addAll(session.flushStatements());
        return session.selectList(statement, parameter);
    }

    public List<BatchResult> getResultBatchList() {
        return resultBatchList;
    }

}
